package cn.edu.zut.DAO;

import cn.edu.zut.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 袁飞
 * @date 2019/4/9/00911:07
 */
@Repository
public class StudentDaoImpl implements StudentDao {
    private JdbcTemplate jdbcTemplate;

    private List<Student> students;
    @Override
    public void insertStudent(Student student) {
        String INSERT_Student= "INSERT INTO person(code,name,sex,point) VALUES(?,?,?,?)";
        Object[] args={student.getId(),student.getName(),student.getSex(),student.getPoint()};
        jdbcTemplate.update(INSERT_Student,args);

    }

    @Override
    public void insertAll(List<Student> studentkList) {

    }

    @Override
    public List<Student> queryAl() {
        String QUERY_ALL_BOOK = "select * from person";
        RowMapper<Student> rowMapper=new BeanPropertyRowMapper<Student>(Student.class);
        students = jdbcTemplate.query(QUERY_ALL_BOOK,rowMapper);
        return students;
    }


    @Override
    public void count(Student student) {

    }
    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Resource(name = "list")
    public void setStudents(List<Student> Students) {
        this.students = Students;
    }
}
